function submitLogin(prefix){ 
	if(typeof(prefix) == "undefined") prefix = "";
	var error = "" ;
	var email = $("[name="+ prefix +"email]").val();
	var password = $("[name="+ prefix +"password]").val();
	if(email == "") {
		error += "The Email field is required.<br/>";	
	}
	
	if(password == "") {
		error += "The Password field is required.<br/>";		
	}
	if(error !="") {
		$("#"+ prefix +"errorDiv").html(error);	
	} else {
		var urldefault=URL_DEFAULT;
		var time = "1";
		if(isMobile()){
			var d = new Date();
			time = d.getTime();
		}
		callBlockUI();
		$.post(urldefault + 'login/validate_credentials/' + time, {'email':email,'password':password}, function(data){
			   // do something with received data!
				$.unblockUI();
			 	var getdata_arr = data.split('|');
				if( getdata_arr[0] =="Fail" || getdata_arr[0].indexOf("Fail") >= 0) {
					$("#"+ prefix +"errorDiv").html(getdata_arr[1]);	
				} else {
					document.location.href=getdata_arr[1] ;
				}						
				
			});		
	}
	
	 	 
} 

function submitChangePassword() {
	$('[name=changePasswordForm]').submit();
}

function processUserForgotPwd() {
	
	var error = "" ;
	if($("[name=email]").val()== "") {
		error += "The email field is required.<br/>";	
	}
	
//	if($("[name=emailaddress]").val()== "") {
//		error += "The Email Address field is required.<br/>";		
//	}
	if(error !="") {
		$("#errorDiv").html(error);	
	} else {		
		$.post(document.getElementById("urldefault").value+ 'login/proccess_forgot_password', {'email':$("[name=email]").val(),'emailaddress':$("[name=emailaddress]").val()}, function(data){
			   // do something with received data!
			 	var getdata_arr = data.split('|');
				if( getdata_arr[0] =="Fail" ) {
					$("#errorDiv").html(getdata_arr[1]);	
				} else {
					$("#errorDiv").html(getdata_arr[1]);
				}
			});	 		
	}
	
}

function showForgotYourPassword() {
	$.post(document.getElementById("urldefault").value+ 'login/showForgotPassword', {}, function(data){
    	$("#Content").html(data);
    	if(typeof($login_dialog) != "undefined"){
    		$login_dialog.dialog("close");
    		$("[name=email]").focus();
    	}
    });	 
}

function showLoginForm(){
	$.post(document.getElementById("urldefault").value+ 'login/index', {'is_ajax_call' : 'yes'}, function(data){
    	$("#Content").html(data);
//    	if(typeof($login_dialog) != "undefined"){
//    		$login_dialog.dialog("close");
//    		$("[name=email]").focus();
//    	}
    });
}

function showBuyerSignup() {
	$.post(document.getElementById("urldefault").value+ 'login/playerSignup', {'is_ajax_call' : 'yes'}, function(data){
    	$("#Content").html(data);
    });	 
}

function forceBillingAsShipping(){
	var flag = $('#same_as_shipping').attr('checked');	
	if(flag){		
		$('[name=biAddress1]').val($('[name=address1]').val());
		$('[name=biAddress2]').val($('[name=address2]').val());
		$('[name=biCity]').val($('[name=city]').val());
		$('[name=biZip]').val($('[name=zip]').val());
		$('[name=biCountry]').val($('[name=country]').val());
		
		
		$('[name=biPhone]').val($('[name=phone]').val());
		changeCountry(document.getElementById('bicountry_id'));
		$('[name=biState]').val($('[name=state]').val());
		if($('[name=biState]').val() == ""){
			$('[name=biState]').selectedIndex = 0;
		}
		$('[name=biStateText]').val($('[name=stateText]').val());
		$('[name=biPhone1]').val($('[name=phone1]').val());
		$('[name=biPhone2]').val($('[name=phone2]').val());
		$('[name=biPhone3]').val($('[name=phone3]').val());
	}			    	    				

	$('[name=biAddress1]').attr('disabled', flag);
	$('[name=biAddress2]').attr('disabled', flag);
	$('[name=biCountry]').attr('disabled', flag);
	$('[name=biCity]').attr('disabled', flag);
	$('[name=biState]').attr('disabled', flag);
	$('[name=biStateText]').attr('disabled', flag);
	$('[name=biZip]').attr('disabled', flag);
	$('[name=biPhone1]').attr('disabled', flag);
	$('[name=biPhone2]').attr('disabled', flag);
	$('[name=biPhone3]').attr('disabled', flag);
	
}
function forceAllAsBussinessAddress(){
	forceShippingAsContact();
	forceBillingAsBusiness();
	forceMerchanAsBusiness();
}

function submitCreatePlayer(){
	$.blockUI();
    $('[name=createPlayerForm]').submit(); 
}

function submitCreatePlayerResponse(responseText, statusText, xhr, $form){
	$.unblockUI();
	var data = eval('(' + responseText + ')');
	$('#UpdateDIV').html(data.content);
	if(data.success){
		if(data.message != null){
			$('#resultDiv').html(data.message);
		}
    }else{
    	if(data.commonResponse.errorDescription != null){
    		$('#errorDiv').html(data.commonResponse.errorDescription);
    	}
    }
}

function changeCountry(obj) {	

	var country_id = obj.id; 
	var stateId =  "stateId" ;
	var stateTextId  = "stateTextId" ;
	var tempCountry = $("#"+country_id).val();
	var hasState ="hasState";
	
	if(country_id == "bicountry_id") {
		stateId = "biStateId" ;
		stateTextId = "biStateTextId" ;
		hasState ="hasbiState";
	}
	
	var count = 0 ;
	for (var state in stateList) {		
		if (tempCountry == stateList[state].country_id) {
		    count += 1;			   
			var tempState = document.getElementById(stateId);
			if(count ==1) {
				tempState.innerHTML = "";	
			}
			tempState.options[tempState.options.length] = new Option(stateList[state].name, stateList[state].id, false, false);
			document.getElementById(stateTextId).style.display = "none";
			document.getElementById(stateId).style.display = "";	
			$("#"+hasState).val("yes") ;
			
		}
	}
	if(count == 0 ) {
		var tempState = document.getElementById(stateId);
		tempState.innerHTML = "";
		document.getElementById(stateTextId).value="";
		document.getElementById(stateTextId).style.display = "";
		document.getElementById(stateId).style.display = "none";
		$("#"+hasState).val("no") ;
	}
	return 0;
}